package com.spider.lwlk.mongodb.task

import com.spider.lwlk.mongodb.task.taskstatus.TaskStatus

class ContractTask extends BaseTask {

    private html

    @Override def onSuccess() {

        {
            arg0, arg1 ->

            [ {
                  resp, reader ->

                  taskStatus = TaskStatus.RequestSuccess

                  html = reader.text

                  doUpdate()

              }, super.onSuccess() ].each { it.call(arg0, arg1) }
        }
    }

    @Override def onUpdate() {

        {
            ->

            [ {
                  db.html.insert([ url: path, html: html ])

              }, super.onUpdate() ].each { it.call() }
        }
    }

    @Override def onCompleted() {

        {
            ->

            [ {

                db.bookurl.delete([ url: path ])

                db.bookcheckedurl.insert([ url: path ])

              }, super.onCompleted() ].each { it.call() }
        }
    }
}

